// TokenToCTreeCtrl.cpp : implementation file
//

#include "stdafx.h"
#include "TokenViews.h"

string TokenView(Token::const_reference To){
	return To.view();
}
string TokenToString(Token::const_reference To){
	return To.toString();
}

string TokenToHtml(Token::const_reference To){
	string Par("<BR><BR><table style=\"border-width:3;border-style:'inset';border-color:'blue'\"><tr><td>");
	if(To.isTerm( ))
		if(_TERM( To).isVirtualInvertedListTerm( )){
			for(size_t i=0; i<_VIRTUALINVERTEDLISTTERM( To ).size ( ); i++)
				Par += TokenToHtml(_VIRTUALINVERTEDLISTTERM( To ).operator[ ](i));
				Par += "</td></tr></table>";
				return Par;
			}
	
	Par +=("<P style=\"width:700;padding:'2,2,2,2';border-style:'groove';border-color:brown;border-width:2\">");
	Par += To.toString( );
	Par += "</P>";
	if(To.isTerm( )){
		Par +="</TD></tr><tr><td>";
		Par +=("<P style=\"width:700;padding:'2,2,2,2';border-style:'groove';border-color:brown;border-width:2\">");
		Par += _TERM(To).getType( ).toString( );
		Par += "</P>";
		}
	Par += "</td></tr></table>";
	return Par;
}

#ifdef __AFXCMN_H__
void TokenToCTreeCtrl(CTreeCtrl* TC, HTREEITEM Branch, Token::const_reference To)
{
	if(!Branch){
		Branch =  TC->InsertItem(_T(" "));
		TC->SetItemText(Branch, _T("top"));
	}

	if(To.isType()){
		if(_TYPE(To).isAtomicType()){
			TC->SetItemText(Branch, _T((string("AtomicType-->") + TokenToString(To)).c_str()));	
			return;
		}
		if(_TYPE(To).isArrowType()){
			TC->SetItemText(Branch, _T("ArrowType-->"));
			HTREEITEM Left =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Left, _ARROWTYPE(To).getLeft());
			HTREEITEM Right =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Right, _ARROWTYPE(To).getRight());
			return;
		}
		if(_TYPE(To).isAbstractType()){
			TC->SetItemText(Branch, _T("AbstractType-->"));
			HTREEITEM Left =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Left, _ABSTRACTTYPE(To).getVar());
			HTREEITEM Right =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Right, _ABSTRACTTYPE(To).getBody());
			return;
		}
	}
	if(To.isTerm()){
		if(_TERM(To).isTermVariable()){
			TC->SetItemText(Branch, _T((TokenToString(To)).c_str()));	
			return;
		}
		if(_TERM(To).isApplicationTerm()){
			TC->SetItemText(Branch, _T((TokenToString(To)).c_str()));
			HTREEITEM Left =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Left, _APPLICATIONTERM(To).getLeft());
			HTREEITEM Right =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Right, _APPLICATIONTERM(To).getRight());
			return;
		}
		if(_TERM(To).isAbstractTerm()){
			TC->SetItemText(Branch, _T((string("AbstractTerm-->")+ TokenToString(To)).c_str()));
			HTREEITEM Left =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Left, _ABSTRACTTERM(To).getVar());
			HTREEITEM Right =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Right, _ABSTRACTTERM(To).getBody());
			return;
		}
		if(_TERM(To).isAbstractTypeTerm()){
			TC->SetItemText(Branch, _T((string("AbstractTypeTerm-->")+ TokenToString(To)).c_str()));
			HTREEITEM Left =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Left, _ABSTRACTTERM(To).getVar());
			HTREEITEM Right =   TC->InsertItem(_T("jjk"), Branch);
			TokenToCTreeCtrl(TC, Right, _ABSTRACTTERM(To).getBody());
			return;
		}

	}
}
#endif


